package logic

import (
	"context"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowHouseLogic {
	return &ShowHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowHouseLogic) ShowHouse(in *user.ShowHouseRequest) (*user.ShowHouseResponse, error) {
	// todo: add your logic here and delete this line

	var h models.House
	h.ID = uint(in.HouseId)
	err := h.ShowHouse()
	if err != nil {
		logx.Error("查看详情失败", err)
		return nil, err
	}

	return &user.ShowHouseResponse{
		Title:   h.Title,
		Size:    float32(h.Size),
		Cate:    h.Cate,
		Price:   float32(h.Price),
		Address: h.Address,
	}, nil
}
